using System;
using System.Collections.Generic;
using Stats;
using UnityEngine;

namespace Entities
{
	public abstract class Mob : Fighter
	{
		protected GameObject prefab;
		
		protected String prefabName;
		
		protected int clan; //todo faire un enum et trouver un vrai nom
		
		protected Dictionary<Mod, int> availableMods;//pool de mods possibles avec les pondérations de proba
		
		protected Mob leader;
		
		protected MobGroup mobGroup;
		
		public MobAction currentAction;
		
		
		
		public Mob ()
		{
		}
		
		public void setPrefab(){
			prefab = (GameObject)Resources.Load(prefabName);
		}
		
		public GameObject getPrefab(){
			return prefab;
		}
		
		public void addMods(int nbMods, System.Random random){
			//choisir parmi les mods du leader
		}
		
		public void setLeader(Mob leader){
			this.leader = leader;	
		}
		
		public Mob getLeader(){
			return leader;	
		}
		
		public bool isLeader(){
			return leader == null;	
		}
		
		public void setMobGroup(MobGroup mobGroup){
			this.mobGroup = mobGroup;	
		}
		
		public MobGroup getMobGroup(){
			return mobGroup;	
		}
		
		public Fighter chooseTarget(){
			Fighter target = null;
			float minDist = float.MaxValue;
			foreach (Fighter f in getMobGroup().getEnemies()){
				float dist = this.distance(f);
				if (dist < minDist) {
					minDist = dist;
					target = f;
				}
			}
			return target;
		}
		
		public Mob isBlocking(){
			foreach (Mob mob in getMobGroup().getMobs()){
				if (this != mob && this.distance(mob) < MobAction.maxclearrange && mob.currentAction.type != TypeAction.idle) return mob;
			}
			return null;
		}
		
		public int getMovementSpeed(){
			return ms.Val;	
		}
		
		public float distanceAway(){
			Vector2 pos = new Vector2(gameObject.transform.position.x, gameObject.transform.position.z);
			Vector2 start = new Vector2(mobGroup.getStartingPosition().x, mobGroup.getStartingPosition().z);
			return Vector2.Distance(pos, start);
		}
		
		public abstract double groupSizeFactor();
	}
}

